package paquete_pruebas;
/*
 * ventanaGrafica.java
 *
 * Created on 9 de agosto de 2003, 9:11
 */
import org.jfree.data.*;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.chart.*;
import org.jfree.chart.plot.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.Image;

import java.awt.image.*;
import java.io.File;
import java.io.IOException;

/**
 *
 * @author  Roberto Canales
 */
public class ventanaGrafica extends java.awt.Frame {

    BufferedImage grafica = null;

    /** Creates new form ventanaGrafica */
    public ventanaGrafica() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                //exitForm(evt);
            	setVisible(false);
            }
        });

        pack();
    }

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {
        System.exit(0);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

//        ventanaGrafica miventana = new ventanaGrafica();
//        miventana.setSize(400,400);
//        miventana.show();
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                //new ventanaGrafica().setVisible(true);
            	ventanaGrafica miventana = new ventanaGrafica();
              miventana.setSize(400,400);
              miventana.setVisible(true);
            }
        });
    }

    public BufferedImage creaImagen()
    {
    	XYSeries series = new XYSeries("Crecimiento XYGrafico");
		series.add(1, 10);
		series.add(2, 20);
		series.add(3, 10);
		series.add(4, 30);
		series.add(5, 40);
		// Add the series to your data set
		XYSeriesCollection dataset = new XYSeriesCollection();
		dataset.addSeries(series);
		// Generate the graph
		// JFreeChart chart = ChartFactory.createXYLineChart(�Crecimiento
		// Ubuntu�, // Title
		JFreeChart chart = ChartFactory.createXYAreaChart("XY Chart", // Title
				"Meses", // x-axis Label
				"Ventas", // y-axis Label
				dataset, // Dataset
				PlotOrientation.VERTICAL, // Plot Orientation
				true, // Show Legend
				true, // Use tooltips
				false // Configure chart to generate URLs?
				);

        BufferedImage image = chart.createBufferedImage(300,300);
        try {
			File f = new File("src/interfaces/imagenes/XYChart.png");
			ChartUtilities.saveChartAsJPEG(f, chart, 500, 300);
		} catch (IOException e) {
			System.err.println("Error creando grafico.");
		}
        return image;
    }

    public void paint(java.awt.Graphics g/*org.eclipse.swt.graphics.GC g*/) {
        //super.paint(g);

        if(grafica == null)
        {
            grafica = this.creaImagen();
        }
        g.drawImage(grafica,30,30,null);
    }

}